package appModel;

import globalTools.FoldersPaths;

import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class StdScoreSheet implements Serializable, ScoreSheet, FoldersPaths {

	// ATTRIBUTS
	
	private static final long serialVersionUID = 1L;
	
	private Map<String, Long> scores;

	// REQUETES

	@Override
	public Long getScore(String f) {
		if (scores == null) {
			return null;
		}
		return scores.get(f);
	}
	
	// COMMANDES

	@Override
	public void putScore(long t, String s) throws IOException {
		if (scores == null) {
			scores = new HashMap<String, Long>();
		}
		Long record = getScore(s);
		if (record == null || record >= t) {
			scores.put(s, t);
		}
	}
	
	/* TEMPORAIRE */
	public void corrigeScore() {
		if (scores != null) {
			Map<String, Long> newMap = new HashMap<String, Long>();
			for (String s : scores.keySet()) {
				newMap.put(s.substring((s.charAt(0) == '/') ? 1 : 0), scores.get(s));
			}
			scores = newMap;
		}
	}

}
